package com.gewu.pm.ui.activity.report;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gewu.pm.R;
import com.gewu.pm.aop.SingleClick;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.utils.TextStarUtils;
import com.hjq.bar.TitleBar;

import java.util.ArrayList;
import java.util.List;

/**
 * 写日报页面
 */
public final class WriteDailyReportActivity extends AppActivity {

    private TitleBar mTitleBar;
    
    // 8个标题TextView
    private TextView mLabel1;
    private TextView mLabel2;
    private TextView mLabel3;
    private TextView mLabel4;
    private TextView mLabel5;
    private TextView mLabel6;
    private TextView mLabel7;
    private TextView mLabel8;
    
    // 8个输入框
    private EditText mContent1Edit;
    private EditText mContent2Edit;
    private EditText mContent3Edit;
    private EditText mContent4Edit;
    private EditText mContent5Edit;
    private EditText mContent6Edit;
    private EditText mContent7Edit;
    private EditText mContent8Edit;
    
    private TextView mLocationValue;
    private TextView mVisibleScopeLabel;
    private TextView mVisibleScopeValue;
    private TextView mRelatedPersonValue;
    private RecyclerView mUploadImagesRecyclerView;
    private TextView mSendBtn;

    private List<String> mUploadedImages = new ArrayList<>();
    private static final int MAX_IMAGE_COUNT = 5;

    public static void start(Context context) {
        Intent intent = new Intent(context, WriteDailyReportActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_write_daily_report;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mTitleBar = findViewById(R.id.tb_title);
        
        // 8个标题
        mLabel1 = findViewById(R.id.tv_label_1);
        mLabel2 = findViewById(R.id.tv_label_2);
        mLabel3 = findViewById(R.id.tv_label_3);
        mLabel4 = findViewById(R.id.tv_label_4);
        mLabel5 = findViewById(R.id.tv_label_5);
        mLabel6 = findViewById(R.id.tv_label_6);
        mLabel7 = findViewById(R.id.tv_label_7);
        mLabel8 = findViewById(R.id.tv_label_8);
        
        // 8个输入框
        mContent1Edit = findViewById(R.id.et_content_1);
        mContent2Edit = findViewById(R.id.et_content_2);
        mContent3Edit = findViewById(R.id.et_content_3);
        mContent4Edit = findViewById(R.id.et_content_4);
        mContent5Edit = findViewById(R.id.et_content_5);
        mContent6Edit = findViewById(R.id.et_content_6);
        mContent7Edit = findViewById(R.id.et_content_7);
        mContent8Edit = findViewById(R.id.et_content_8);
        
        mLocationValue = findViewById(R.id.tv_location_value);
        mVisibleScopeLabel = findViewById(R.id.tv_visible_scope_label);
        mVisibleScopeValue = findViewById(R.id.tv_visible_scope_value);
        mRelatedPersonValue = findViewById(R.id.tv_related_person_value);
        mUploadImagesRecyclerView = findViewById(R.id.rv_upload_images);
        
        // ✅ 使用 BottomButton 内部按钮 ID
        mSendBtn = findViewById(R.id.tv_bottom_button);

        // 设置标题栏
        mTitleBar.setOnTitleBarListener(this);

        // 使用 TextStarUtils 给标题添加红色星号
        TextStarUtils.setRequiredText(mLabel1, "今日重点工作");
        TextStarUtils.setRequiredText(mLabel2, "今日走访工作总结");
        TextStarUtils.setRequiredText(mLabel3, "非走访工作总结");
        TextStarUtils.setRequiredText(mLabel4, "存在问题及处理情况");
        TextStarUtils.setRequiredText(mLabel5, "需相关关部门及上级领导协助处理事宜");
        TextStarUtils.setRequiredText(mLabel6, "明日走访计划");
        TextStarUtils.setRequiredText(mLabel7, "明日非走访计划");
        TextStarUtils.setRequiredText(mLabel8, "个人反思");
        TextStarUtils.setRequiredText(mVisibleScopeLabel, "可见范围");

        // 设置点击事件
        setOnClickListener(mVisibleScopeValue, mRelatedPersonValue, mSendBtn);

        // 设置图片网格（每行3列，最多5张）
        mUploadImagesRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        // TODO: 设置图片上传适配器
    }

    @Override
    protected void initData() {
        // 初始化数据
    }

    @SingleClick
    @Override
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId == R.id.tv_visible_scope_value) {
            // 选择可见范围
            toast("选择可见范围");
        } else if (viewId == R.id.tv_related_person_value) {
            // 艾特相关人员
            toast("@相关人员");
        } else if (viewId == R.id.tv_bottom_button) {
            // 发送日报
            sendReport();
        }
    }

    /**
     * 发送日报
     */
    private void sendReport() {
        // 获取所有输入内容
        String content1 = mContent1Edit.getText().toString().trim();
        String content2 = mContent2Edit.getText().toString().trim();
        String content3 = mContent3Edit.getText().toString().trim();
        String content4 = mContent4Edit.getText().toString().trim();
        String content5 = mContent5Edit.getText().toString().trim();
        String content6 = mContent6Edit.getText().toString().trim();
        String content7 = mContent7Edit.getText().toString().trim();
        String content8 = mContent8Edit.getText().toString().trim();
        
        toast("发送日报");
        // TODO: 提交数据到后台
        finish();
    }
}

